<?php

namespace Admin\Controller;
use Admin\Builder\AdminConfigBuilder;

class AuctionController  extends AdminController {
	public function index(){
		$auction	=	M('TbAuction');
		$map['cID'] = UID;
		        
 		$sql='SELECT * from duijie_tb_auction,duijie_tb_tecach
             WHERE duijie_tb_auction.tecID=duijie_tb_tecach.id';
 		$list=$auction->query($sql);
 		
		int_to_string($list,array('jstatus'=>array(-1=>'不通过' ,0=>'申请中',1=>'进行中',2=>'已结束')));
		
		$this->assign('_list', $list);
		$this->display();
	}

	public function add(){
		if(IS_POST){
			$auction = D("TbAuction");
			$data = $auction->create();
			$data['cID'] = UID;
			$rst = $auction->add($data);
			if($rst){
				$this->success("添加成功",U("tecach"));
			}else{
				$this->error("添加失败");
			}
			
		}else{
			/* $result = M('tb_teclab')->where(array('upid'=> 0))->field('id,name')->select();
			 $this->assign('cate',$result); */
			$ach=M('TbTecach');
			$map['cID']=UID;
			$list=$ach->where($map)->field('id,tecname')->select();
			$this->assign('_list',$list);
			$this->display();
		}

	}
	
	public function save(){
		$model	=	M('TbConinf');
		$con	=	$model->create();
		if(empty($con['id'])){
			$con['cID']=UID;
			$model->add($con);
			$this->success("合同添加成功！",U('index'));
		}else {
			$model->save($con);
			$this->success("合同修改成功！",U('index'));
		}
	}
	public function del(){
		$map['id']	=   I('id');
		$this->delete('TbPatent',$map,array('success' => '专利删除成功！', 'error' => '专利删除失败！'));
	}
	// 	public function edit(){
	// 		$builder = new AdminConfigBuilder();
	// 		$data = $builder->handleConfig();
	// 		$builder->keyMultiImage('', '', '');

	// 		$builder->display();
	// 	}
	
	//项目详情
	public function jdetail($id=''){
	
		$tecach = M(tb_tecach);
	
		$where['duijie_tb_tecach.id']= $id;
		$data = $tecach ->join('duijie_tb_techol on duijie_tb_techol.id = duijie_tb_tecach.cID')
		->join('duijie_tb_teccoo on duijie_tb_teccoo.cid=duijie_tb_tecach.hztype')
		->join('duijie_tb_teccsd on duijie_tb_teccsd.sid=duijie_tb_tecach.csd')
		->join('duijie_tb_patent on duijie_tb_patent.id = duijie_tb_tecach.patentid')
		->join('duijie_tb_award on duijie_tb_award.ID = duijie_tb_tecach.awardid')
		->join('duijie_tb_paper on duijie_tb_paper.id = duijie_tb_tecach.paperid')
		->where($where) ->select();
	
		int_to_string($data,array('duijie'=>array(-1=>'未对接',0=>'对接中',1=>'对接已结束')));
	
		foreach ($data as $key => $value) {
			$str=$data[$key]['fplace'];
			$str2=$data[$key]['place'];
			$map['id']=$str;
			$map2['id']=$str2;
			$data[$key]['tids']=M("District")->where($map)->select();
			$data[$key]['tids2']=M("District")->where($map2)->select();
		}
	
		foreach ($data as $key => $value) {
			$str3=$data[$key]['ffield'];
			$str4=$data[$key]['field'];
			$map3['ID']=$str3;
			$map4['ID']=$str4;
			$data[$key]['tids3']=M("TbTeclab")->where($map3)->select();
			$data[$key]['tids4']=M("TbTeclab")->where($map4)->select();
		}
	
		$this -> assign('data',$data);
	
		$this->meta_title = '项目详情';
		$this->display();
	}
	
	//通过
	public function jpass($id=''){
		$pai = M(tb_auction);
		$where['tecID'] =  $id;
		$data['jstatus'] = '1';
		$pai->where($where)->save($data);
		$this->success('审核通过',U('index'));
	}
	
	//不通过
	public function jcancel($id=''){
		$pai = M(tb_auction);
		$where['tecID'] =  $id;
		$data['jstatus'] = '-1';
		$pai->where($where)->save($data);
		$this->success('审核不通过',U('index'));
			
			
	}

}